(function(window, undefined){
  'use strict';
  var ns = window.beneath = window.beneath || {};

  function GameOver() {
  }

  GameOver.prototype = {
    init : function (state) {
      this.state = state[0];
    },

    create: function () {
      this.title = this.add.bitmapText(0, 0, 'font', 'Game Over!', 32);
      this.title.x = this.title.textWidth * -0.5 + this.world.centerX;
      this.title.y = 20;

      this.add.tween(this.title)
          .to({x : this.title.x + 100}, 500, Phaser.Easing.Quadratic.InOut)
          .to({x : this.title.x - 100}, 500, Phaser.Easing.Quadratic.InOut)
          .loop()
          .start();

      this.score = this.add.bitmapText(0, 0, 'font', 'You managed to keep the company afloat for ' + this.state.day + ' days!', 32);
      this.score.x = this.world.centerX - this.score.textWidth / 2;
      this.score.y = 60;

      this.clickToTryAgain = this.add.bitmapText(0 , 0, 'font', 'Click anywhere to try again', 32);
      this.clickToTryAgain.x = this.world.centerX - this.clickToTryAgain.textWidth / 2;
      this.clickToTryAgain.y = this.world.centerY;

      this.input.onDown.add(function () {
        this.game.state.start('office', true, false, [{
          day : 0,
          firstDay : true,
          money : 10000,
          morale : 100,
          coal : [],
          employees : [
            ns.Miner.randomMiner(),
            ns.Miner.randomMiner(),
            ns.Miner.randomMiner()
          ],
          employeeSalery : 100,
          maintainance : 500,
          favors : 0,
          haveUnion : false,
          maxCommands : 9999,
          minerDied : []
        }]);
      }, this);
    }
  };

  window.beneath.GameOver = GameOver;

})(window);